﻿using LiteDB;
using System;
using System.Collections.Generic;
using System.Linq;

namespace LiteDb
{
    // 变量扩展
    public class VariantExtra
    {
        public class CustomHex
        {
            public int rx_bytes { get; set; } = 0;
            public string tx_rule { get; set; } = "";
            public string parse { get; set; } = "";
        }

        public class CustomFrame
        {
            public string tx_rule { get; set; } = "";
        }

        public class HJ212Code
        {
            public ulong signalType { get; set; } = 0; // size_t 通常用 ulong
            public float upperLimit { get; set; } = 0.0f;
            public float lowerLimit { get; set; } = 0.0f;
        }

        public class RegTypeExValue
        {
            public string DBNum { get; set; } = "";
            public string RegAddr { get; set; } = "";
            public string BitAddr { get; set; } = "";
            public ulong RegTypeEx { get; set; } = 0;
        }

        public class Params
        {
            public int data_type { get; set; } = 1;
            public int decimal_ { get; set; } = 1; // decimal是C#关键字，建议加下划线
            public string unit { get; set; } = "int";
            public int reg_addr { get; set; } = 0x1234;
            public ulong reg_addr_rw { get; set; } = 0; // 1读 2写 3读写
            public string s_reg_addr { get; set; } = "";
            public int reg_type { get; set; } = 1;
            public float modulus { get; set; } = 0.0f;
            public string refer_name { get; set; } = "";
            public string ruler_id { get; set; } = "";
            public int ruler { get; set; } = 0;
            public int sort { get; set; } = 0;
            public int math_type { get; set; } = 0;
            public string event_name { get; set; } = "";
            public string math_value { get; set; } = "";
            public string content_value { get; set; } = "";
            public string formula { get; set; } = "";
            public string opc_var_path { get; set; } = "";

            public CustomHex hex { get; set; } = new CustomHex();
            public CustomFrame frame { get; set; } = new CustomFrame();
            public HJ212Code hj212 { get; set; } = new HJ212Code();
            public RegTypeExValue reg_typeEx { get; set; } = new RegTypeExValue();
        }

        public int id { get; set; } = -1;
        public int monitor_device_id { get; set; } = -1;
        public string name { get; set; } = "VarName";
        public Params attrs { get; set; } = new Params();
        public int proto_type { get; set; } = 0;

        //  需要写一个转换函数(把object转换为VariantExtra)
        public static VariantExtra Convert(object obj)
        {
            return BsonMapper.Global.ToObject<VariantExtra>((BsonDocument)obj);
        }
    }    
}